﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Engine;

/* Copyright (c) 2014
 * author: Ricky Kratochwil
 * @ date: 2014-07-08
 * @ summary: Highscore form showing points and additional information about last game
*/

namespace GameOfCoins
{
	public partial class Highscore : Form
	{
		private CPlayerCore	m_oPlayerCore;
		private Rectangle	m_oRectP1;
		private Rectangle	m_oRectP2;
		private int			m_iP1Percent;
		private int			m_iP2Percent;
//		private Font		m_oTextFont;

		public Highscore(CPlayerCore oPlayerCore)
		{
			InitializeComponent();

			m_oRectP1 = new Rectangle();
			m_oRectP2 = new Rectangle();
			m_oPlayerCore = oPlayerCore;
//			m_oTextFont   = dgStatistic.Font;
			InitDialog();
		}

//////////////////////////////////////////////////////////////////////////////////////////////////////
////////// UTILITIES

		//Fill dialog with information
		//@ KR / 2014.07.08
		private void InitDialog()
		{
			int iP1Points, iP2Points;
			int iMoves = 0, iStamina = 0, iKicks = 0;

			//////////Set pictureboxes
			pbP1Large.Image = new Bitmap(m_oPlayerCore.GetPlayerImage(1), 48, 48);
			pbP1Small.Image = m_oPlayerCore.GetPlayerImage(1);
			pbP2Large.Image = new Bitmap(m_oPlayerCore.GetPlayerImage(2), 48, 48);
			pbP2Small.Image = m_oPlayerCore.GetPlayerImage(2);

			//////////Set points
			iP1Points = m_oPlayerCore.GetPoints(1);
			iP2Points = m_oPlayerCore.GetPoints(2);
			lblP1Points.Text = iP1Points.ToString();
			lblP2Points.Text = iP2Points.ToString();

			//////////Get bar chart size		
			int iMax		= iP1Points + iP2Points;
			//P1
			m_iP1Percent	 = ((100/iMax) * iP1Points);
			m_oRectP1.Width  = 30;
			m_oRectP1.Height = m_iP1Percent;
			m_oRectP1.X = pbP1Small.Location.X - 3;
			m_oRectP1.Y = pbP1Small.Location.Y - m_oRectP1.Height - 2;

			//P2
			m_iP2Percent	 = ((100/iMax) * iP2Points);
			m_oRectP2.Width  = 30;
			m_oRectP2.Height = m_iP2Percent;
			m_oRectP2.X = pbP2Small.Location.X - 3;
			m_oRectP2.Y = pbP2Small.Location.Y - m_oRectP2.Height - 2;

			//////////Stats
			//P1
			m_oPlayerCore.GetStats(1, ref iMoves, ref iStamina, ref iKicks);
			dgStatistic.Rows.Add(new string[]{"1", iMoves.ToString(), iStamina.ToString(), iKicks.ToString()});

			//P2
			m_oPlayerCore.GetStats(2, ref iMoves, ref iStamina, ref iKicks);
			dgStatistic.Rows.Add(new string[]{"2", iMoves.ToString(), iStamina.ToString(), iKicks.ToString()});
		}

		private void Highscore_Paint(object sender, PaintEventArgs e)
		{
			Graphics g = CreateGraphics();

			g.FillRectangle(new SolidBrush(Color.Red), m_oRectP1);
//			g.DrawString(m_iP1Percent.ToString() + "%", m_oTextFont, new SolidBrush(Color.Black), m_oRectP1.X, m_oRectP1.Y-12);
			g.FillRectangle(new SolidBrush(Color.Blue), m_oRectP2);

			//Reference lines			
			g.DrawLine(new Pen(Color.Black, 2), pbP1Small.Location.X-20, pbP1Small.Location.Y, pbP1Small.Location.X-5, pbP1Small.Location.Y);
			g.DrawLine(new Pen(Color.Black, 2), pbP1Small.Location.X-20, pbP1Small.Location.Y-52, pbP1Small.Location.X-5, pbP1Small.Location.Y-52);
			g.DrawLine(new Pen(Color.Black, 2), pbP1Small.Location.X-20, pbP1Small.Location.Y-102, pbP1Small.Location.X-5, pbP1Small.Location.Y-102);

			g.Dispose();
		}
	}
}
